﻿using AgorApp.Roma.Model.DataTransferObjects.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AgorApp.Roma.Model.DataTransferObjects
{
    /// <summary>
    /// 
    /// </summary>
    public class Tag : IEntityObjectState, IEquatable<Tag>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Tag"/> class.
        /// </summary>
        public Tag()
        {
            this.IdTag = IntIdKeeper.Next();
            this.TagType = TagTypeEnum.HashTag;

            this.AssembleeCapitoline = new List<AssembleeCapitoline>();
            this.ConsiglieriAssemblea = new List<ConsiglieriAssemblea>();
            this.DelibereAssembleaCapitolina = new List<DelibereAssembleaCapitolina>();
            this.GruppiConsiliari = new List<GruppiConsiliari>();
            this.News = new List<News>();
        }

        /// <summary>
        /// Gets or sets the identifier tag.
        /// </summary>
        /// <value>
        /// The identifier tag.
        /// </value>
        public int IdTag { get; set; }
        /// <summary>
        /// Gets or sets the name of the tag.
        /// </summary>
        /// <value>
        /// The name of the tag.
        /// </value>
        public string TagName { get; set; }
        /// <summary>
        /// Gets or sets the type of the tag.
        /// </summary>
        /// <value>
        /// The type of the tag.
        /// </value>
        public TagTypeEnum TagType { get; set; }

        #region Related Entities
        /// <summary>
        /// Gets or sets the assemblee capitoline.
        /// </summary>
        /// <value>
        /// The assemblee capitoline.
        /// </value>
        public virtual ICollection<AssembleeCapitoline> AssembleeCapitoline { get; set; }
        /// <summary>
        /// Gets or sets the consiglieri assemblea.
        /// </summary>
        /// <value>
        /// The consiglieri assemblea.
        /// </value>
        public virtual ICollection<ConsiglieriAssemblea> ConsiglieriAssemblea { get; set; }
        /// <summary>
        /// Gets or sets the delibere assemblea capitolina.
        /// </summary>
        /// <value>
        /// The delibere assemblea capitolina.
        /// </value>
        public virtual ICollection<DelibereAssembleaCapitolina> DelibereAssembleaCapitolina { get; set; }
        /// <summary>
        /// Gets or sets the gruppi consiliari.
        /// </summary>
        /// <value>
        /// The gruppi consiliari.
        /// </value>
        public virtual ICollection<GruppiConsiliari> GruppiConsiliari { get; set; }
        /// <summary>
        /// Gets or sets the news.
        /// </summary>
        /// <value>
        /// The news.
        /// </value>
        public virtual ICollection<News> News { get; set; } 
        #endregion

        /// <summary>
        /// Gets or sets the state of the object.
        /// </summary>
        /// <value>
        /// The state of the object.
        /// </value>
        public EntityObjectState ObjectState { get; set; }

        #region IEquatable
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.
        /// </returns>
        public bool Equals(Tag other)
        {
            if ((object)other == null || other.GetType() != this.GetType()) return false;

            return this.IdTag == other.IdTag;
        }
        /// <summary>
        /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (obj == null || obj.GetType() != this.GetType()) return false;
            if (Object.ReferenceEquals(this, obj)) return true;

            var tag = obj as Tag;
            if ((object)tag == null) return false;
            return this.IdTag == tag.IdTag;
        }
        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
        /// </returns>
        public override int GetHashCode()
        {
            return this.IdTag;
        }
        /// <summary>
        /// Implements the operator ==.
        /// </summary>
        /// <param name="a">a.</param>
        /// <param name="b">The b.</param>
        /// <returns>
        /// The result of the operator.
        /// </returns>
        public static bool operator ==(Tag a, Tag b)
        {
            if (ReferenceEquals(a, b)) return true;
            if (((object)a == null) || ((object)b == null)) return false;
            return a.Equals(b);
        }
        /// <summary>
        /// Implements the operator !=.
        /// </summary>
        /// <param name="a">a.</param>
        /// <param name="b">The b.</param>
        /// <returns>
        /// The result of the operator.
        /// </returns>
        public static bool operator !=(Tag a, Tag b)
        {
            return !(a == b);
        }
        #endregion
    }
}